#ifndef SENDEMAIL


typedef char string1000[10001];
typedef char string100[101];

/*Email Variables*/
static char *emailAccountUsername = "airsoftwareapplications@gmail.com"; /* login username for email account*/
static char *emailAccountPassword = "air12345678"; /* password for email account */
static char *mailHost = "smtp.gmail.com"; /* Mail's server or host */
static char *mailPort = "465"; /* Mail's server or host */

/*SendEmailCMD Library Location*/
static char *sendEmailCMDLocation = " lib/SendEmail/SendEmailCMD.jar ";

typedef struct EmailOption{
    string100 to;
    string100 from;
    string100 subject;
    string1000 message;
}EmailOption;



boolean isValidEmailAddress(const char *EmailAddress)
{
	int AtOffset = -1;
	int DotOffset = -1;
	int i;
	unsigned int Length = strlen(EmailAddress); // Length = StringLength (strlen) of EmailAddress
	for(i = 0; i < Length; i++)
	{
		if(EmailAddress[i] == '@') // If one of the characters is @, store it's position in AtOffset
			AtOffset = (int)i;
		else if(EmailAddress[i] == '.') // Same, but with the dot
			DotOffset = (int)i;
	}
	if(AtOffset == -1 || DotOffset == -1) // If cannot find a Dot or a @
		return 0;
	if(AtOffset > DotOffset) // If the @ is after the Dot
		return 0;
	return !(DotOffset >= ((int)Length-1)); //Chech there is some other letters after the Dot
}



int sendEmail(EmailOption emailOption)
{
    string1000 script;
    if(strlen(emailOption.from))
    {
        strcpy(emailOption.from, emailAccountUsername);
    }
    strcpy(script,"");
    strcat(script,"start ");
    strcat(script,sendEmailCMDLocation);
    strcat(script,"\"");
    strcat(script,emailOption.to);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,emailOption.from);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,emailOption.subject);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,emailOption.message);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,emailAccountUsername);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,emailAccountPassword);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,mailHost);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,mailPort);
    strcat(script,"\"");
    strcat(script," ");
    strcat(script,"\"");
    strcat(script,"false");
    strcat(script,"\"");
    strcat(script," ");
    system(script);
}



#endif // SENDEMAIL
